home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / ATCP_sdk_40_gc.lha / AmiTCP-4.0-gcc / netinclude / rpcsvc / rstat.c < prev    next >
C/C++ Source or Header  |  1995-04-07  |  2KB  |  86 lines

  1. /* @(#)rstat.c    2.3 88/11/30 4.0 RPCSRC */
  2. /*
  3.  *  Simple program that prints the status of a remote host, in a format
  4.  *  similar to that used by the 'w' command, using the rstat.x service.
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <sys/param.h>
  9. #include <rpc/rpc.h>        /* include <sys/time.h> */
  10. #include "rstat.h"
  11.  
  12. main(argc, argv)
  13. int argc;
  14. char **argv;
  15. {
  16.  
  17.     char        *host;
  18.     CLIENT      *rstat_clnt;
  19.     statstime   *host_stat;
  20.     struct tm   *tmp_time;
  21.     struct tm    host_time;
  22.     struct tm    host_uptime;
  23.     char         days_buf[16];
  24.     char         hours_buf[16];
  25.  
  26.     if (argc != 2)
  27.     {
  28.         fprintf(stderr, "usage: %s \"host\"\n", argv[0]);
  29.         exit(1);
  30.     }
  31.  
  32.     host = argv[1];
  33.  
  34.     /* client handle to rstat */
  35.     rstat_clnt = clnt_create(host, RSTATPROG, RSTATVERS_TIME, "udp");
  36.     if (rstat_clnt == NULL)
  37.     {
  38.         clnt_pcreateerror(argv[0]);
  39.         exit(1);
  40.     }
  41.  
  42.     host_stat = rstatproc_stats_3(NULL, rstat_clnt);
  43.     if (host_stat == NULL)
  44.     {
  45.         clnt_perror(rstat_clnt, argv[0]);
  46.         exit(1);
  47.     }
  48.  
  49.     tmp_time = localtime(&host_stat->curtime.tv_sec);
  50.     host_time = *tmp_time;
  51.  
  52.     host_stat->curtime.tv_sec -= host_stat->boottime.tv_sec;
  53.  
  54.     tmp_time = gmtime(&host_stat->curtime.tv_sec);
  55.     host_uptime = *tmp_time;
  56.  
  57.     if (host_uptime.tm_yday != 0)
  58.         sprintf(days_buf, "%d day%s, ", host_uptime.tm_yday,
  59.             (host_uptime.tm_yday > 1) ? "s" : "");
  60.     else
  61.         days_buf[0] = '\0';
  62.  
  63.     if (host_uptime.tm_hour != 0)
  64.         sprintf(hours_buf, "%2d:%02d,",
  65.             host_uptime.tm_hour, host_uptime.tm_min);
  66.     else
  67.     if (host_uptime.tm_min != 0)
  68.         sprintf(hours_buf, "%2d mins,", host_uptime.tm_min);
  69.     else
  70.         hours_buf[0] = '\0';
  71.  
  72.     printf(" %2d:%02d%cm  up %s%s load average: %.2f %.2f %.2f\n",
  73.         (host_time.tm_hour > 12)  ? host_time.tm_hour - 12
  74.                                   : host_time.tm_hour,
  75.         host_time.tm_min,
  76.         (host_time.tm_hour >= 12) ? 'p'
  77.                                   : 'a',
  78.         days_buf,
  79.         hours_buf,
  80.         (double)host_stat->avenrun[0]/FSCALE,
  81.         (double)host_stat->avenrun[1]/FSCALE,
  82.         (double)host_stat->avenrun[2]/FSCALE);
  83.  
  84.     exit(0);
  85. }
  86.